#include<stdio.h>
#include<stdlib.h>
#define NOT_FINDING 0

typedef struct book
{
	int num;
}Book;


typedef struct node {
	Book book;
	struct node * next;
} Node;

int insert(Node *header,Book book);
int delete(Node *header,Book delete_book);
int update(Node *header,int index,Book book);
Book get(Node *header,int index);
int get_size(Node *header);
void display_lists(Node * header);
Node* init_header();
int main(){

	Node * header = init_header();
	Book book1;
	book1.num = 3;
	insert(header,book1);

	display_lists(header);

}

Book get(Node *header, int index){
	int size = get_size(header);
	if(size!=0 && size <= index){
		Node * temp = header;
		int count=0;
		while(temp->next){
			temp=temp->next;
			count++;
			if(count==index)
				return temp->book;
		}
	}


}


int get_size(Node *header){
	if(header->next!=NULL){
		Node * temp = header;
		int count = 0;
		while(temp->next){
			temp=temp->next;
			count++;
		}
		return count;
	}else{
		return 0;
	}
}

int update(Node * header, int index,Book book){
	if(header->next!=NULL){
		Node * temp = header;
		int count = 0; 
		while(temp->next){
			temp = temp->next;
			count++;
			if(count==index){
				temp->book = book;
				return 1;
			}
		}
	}else{
		return -1;
	}
	return 0;
}

int delete(Node* header,Book book){
	if(header->next!=NULL){
		Node *temp = header;
		while(temp->next){
			if(temp->next->book.num == book.num){
				Node * delete_node = temp->next;
				temp->next = delete_node->next;
				free(delete_node);
				return 1;
			}
			temp = temp->next;
		}
	}else{
		return -1;
	}
	return 0;//代表没有该元素
}

void display_lists(Node * header){
	Node *temp = header;
	if(temp->next!=NULL){
		while(temp->next){
			temp=temp->next;
			printf("%d ",temp->book.num);

		}
		printf("\n");
	}else{
		printf("%s\n","No Elements");
	}
}

int insert(Node * header,Book book){
	Node * temp = header;
	if(temp->next!=NULL){
		while(temp->next){
			temp = temp->next;
		}
		Node *p=(Node*)malloc(sizeof(Node));
		p->book = book;
		p->next = NULL;
		temp->next = p;
	}else{
		Node *p=(Node*)malloc(sizeof(Node));
		p->book = book;
		p->next = NULL;
		temp->next = p;
	}
	return 1;
}

Node* init_header(){
	Node * header = (Node*)malloc(sizeof(Node));
	header->next = NULL;
	return header;
}
